package eraserhead.xml.response;

import org.w3c.dom.Node;

import xml.Message;
import eraserhead.boundary.DecisionGUI;
import eraserhead.entity.Decision;
import eraserhead.xml.XmlNode;

/**
 * Response handler for AddChoice
 * @author Michael Checca
 */
public class AddChoiceResponse implements client.IMessageHandler {

	@Override
	public void process(Message response) {
		Node addChoice = XmlNode.findNode(response.contents, "addChoiceResponse");
		if (addChoice != null) {
			Decision model = DecisionGUI.getInstance().getModel();
			String id = XmlNode.getAttribute(addChoice, "id");
			int number = Integer.parseInt(XmlNode.getAttribute(addChoice, "number"));
			String choice = XmlNode.getAttribute(addChoice, "choice");
			model.setChoice(number, choice);
			DecisionGUI.getInstance().getChoicePanel().setChoiceField(number, choice);
			DecisionGUI.getInstance().getChoicePanel().getChoiceField(number).setEditable(false);
			//String userName = DecisionGUI.getInstance().getModel().getSignedInAs().getName();
			//System.out.println("###" + userName + " get the response");
			System.out.println(String.format("AddChoice response received [id: %s, num: %d, choice: %s]",
					id, number, choice));
		}
	}
}
